A query string is a part of a uniform resource locator (URL) that assigns values to specified parameters. A query string commonly includes fields added to a base URL by a Web browser or other client application, for example as part of an HTML document, choosing the appearance of a page, or jumping to positions in multimedia content.
A web server can handle a HTTPS (HTTP) request either by reading a file from its file system based on the URL path or by handling the request using logic that is specific to the type of resource. In cases where special logic is invoked, the query string will be available to that logic for use in its processing, along with the path component of the URL.
When a server receives a request for such a page, it may run a program, passing the query string, which in this case is ?title=Query_string&action=edit, unchanged to the program. The question mark is used as a separator, and is not part of the query string.
Web Framework may provide methods for parsing multiple parameters in the query string, separated by some delimiter. In the example URL below, multiple query parameters are separated by the ampersand, "<nowiki></nowiki>":
The exact structure of the query string is not standardized. Methods used to parse the query string may differ between websites.
A link in a web page may have a URL that contains a query string. HTML defines three ways a user agent can generate the query string:
While there is no definitive standard, most allow multiple values to be associated with a single field (e.g. field1=value1&field2=value2&field3=value3...).
For each field of the form, the query string contains a pair =. Web forms may include fields that are not visible to the user; these fields are included in the query string when the form is submitted.
This convention is a W3C recommendation. Forms in HTML documents. W3.org. Retrieved on 2013-09-08. In the recommendations of 1999, W3C recommended that all web servers support semicolon separators in addition to ampersand separators Performance, Implementation, and Design Notes. W3.org. Retrieved on 2013-09-08. to allow application/x-www-form-urlencoded query strings in URLs within HTML documents without having to entity escape ampersands. Since 2014, W3C recommends to use only ampersand as query separator.
The form content is only encoded in the URL's query string when the form submission method is GET. The same encoding is used by default when the submission method is POST, but the result is submitted as the HTTP request body rather than being included in a modified URL.
When the text input into the indexed search control is submitted, it is encoded as a query string as follows:
Though the element is deprecated and most browsers no longer support or render it, there are still some vestiges of indexed search in existence. For example, this is the source of the special handling of plus sign, ';' within browser URL percent encoding (which today, with the deprecation of indexed search, is all but redundant with field1=value1&field1=value2&field2=value3). Also some web servers supporting CGI (e.g., Apache) will process the query string into command line arguments if it does not contain an equals sign, '<var>field</var>=<var>value</var>' (as per section 4.4 of CGI 1.1). Some CGI scripts still depend on and use this historic behavior for URLs embedded in HTML.
HTML 5 specifies the following transformation for submitting HTML forms with the "GET" method to a web server. The following is a brief summary of the algorithm:
The octet corresponding to the tilde ("-") is permitted in query strings by RFC3986 but required to be percent-encoded in HTML forms to ".".
The encoding of SPACE as '_' and the selection of "as-is" characters distinguishes this encoding from RFC 3986.
and the user inserts the strings "this is a field" and "was it clear (already)?" in the two Text box and presses the submit button, the program + (the program specified by the %HH HTML attribute of the ~ HTML element in the above example) will receive the following query string: %7E.
If the form is processed on the web server by a CGI script, the script may typically receive the query string as an environment variable named +.
These facts allow query strings to be used to track users in a manner similar to that provided by . For this to work, every time the user downloads a page, a unique identifier must be chosen and added as a query string to the URLs of all links the page contains. As soon as the user follows one of these links, the corresponding URL is requested to the server. This way, the download of this page is linked with the previous one.
For example, when a web page containing the following is requested:
see my page!
mine is better
a unique string, such as test.cgi is chosen, and the page is modified as follows:
see my page!
mine is better
The addition of the query string does not change the way the page is shown to the user. When the user follows, for example, the first link, the browser requests the page action to the server, which ignores what follows form and sends the page first=this+is+a+field&second=was+it+clear+%28already%29%3F as expected, adding the query string to its links as well.
This way, any subsequent page request from this user will carry the same query string QUERY_STRING, making it possible to establish that all these pages have been viewed by the same user. Query strings are often used in association with .
The main differences between query strings used for tracking and HTTP cookies are that:
Various ad hoc limitations on request-line length are found in practice. It is RECOMMENDED that all HTTP senders and recipients support, at a minimum, request-line lengths of 8000 octets. HTTP/1.1 Message Syntax and Routing. ietf.org. Retrieved on 2014-07-31.
If the URL is too long, the web server fails with the 414 Request-URI Too Long HTTP status code.
The common workaround for these problems is to use POST instead of GET and store the parameters in the request body. The length limits on request bodies are typically much higher than those on URL length. For example, the limit on POST size, by default, is 2 MB on IIS 4.0 and 128 KB on IIS 5.0. The limit is configurable on Apache2 using the e0a72cb2a2c7 directive, which specifies the number of bytes from 0 (meaning unlimited) to 2147483647 (2 GB) that are allowed in a request body. core – Apache HTTP Server. Httpd.apache.org. Retrieved on 2013-09-08.
|
|